package org.perche.chat.server.servlet;

import org.apache.thrift.GWTHelper;
import org.apache.thrift.TException;
import org.perche.chat.server.ServiceFactory;
import org.perche.chat.thrift.data.gwt.GreetingRequest;
import org.perche.chat.thrift.data.gwt.GreetingResponse;
import org.perche.chat.thrift.services.gwt.GreetingService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Singleton;

@Singleton
public class GreetingServlet extends RemoteServiceServlet implements GreetingService.Iface {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5762612874944000194L;

	@Override
	public GreetingResponse greetServer(GreetingRequest request) {
		request.setServerInfo(getServletContext().getServerInfo());
		request.setUserAgent(getThreadLocalRequest().getHeader("User-Agent"));

		try {
			return (GreetingResponse) GWTHelper.convert(ServiceFactory.getInstance().getGreetingService().greetServer((org.perche.chat.thrift.data.GreetingRequest) GWTHelper.convert(request)));
		} catch (TException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//TODO(TGA) throw Chat exeption
			return null;
		}
	}

}
